package com.usian.article.controller.v1;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.usian.article.entity.ApAuthor;
import com.usian.common.dtos.ResponseResult;
import com.usian.common.enums.AppHttpCodeEnum;
import com.usian.common.exception.LeadException;
import com.usian.common.util.BeanHelper;
import com.usian.model.article.dtos.AuthorDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.article.service.IApAuthorService;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * APP文章作者信息表 前端控制器
 * </p>
 *
 * @author usian
 * @since 2022-07-05
 */
@RestController
@RequestMapping("/api/v1/author")
@Api(tags = "APP文章作者信息表接口")
@CrossOrigin
public class ApAuthorController {

    @Autowired
    private IApAuthorService apAuthorService;

    /**
     * 根据apUserid 查询作者信息
     *
     * @param apUserId
     * @return
     */
    @GetMapping("/findByUserId/{id}")
    public AuthorDto findByUserId(@PathVariable("id") Integer apUserId) {
        return apAuthorService.findByUserId(apUserId);
    }

    /**
     * 保存作者
     *
     * @param authorDto
     * @return id
     */
    @PostMapping("/save")
    public Integer saveApAuthor(@RequestBody AuthorDto authorDto) {
        return apAuthorService.saveApAuthor(authorDto);
    }


    @PostMapping("/one/{id}")
    public AuthorDto findById(@PathVariable("id") Integer id) {
        ApAuthor apAuthor = apAuthorService.getById(id);
        if (apAuthor == null) {
            throw new LeadException(AppHttpCodeEnum.PARAM_INVALID,"作者信息不存在");
        }
        AuthorDto authorDto = BeanHelper.copyProperties(apAuthor, AuthorDto.class);
        return authorDto;
    }
}
